package com.caseProcess.service.impl;

import com.caseProcess.entity.Case;
import com.caseProcess.entity.CaseProcInfo;
import com.caseProcess.entity.Department;
import com.caseProcess.mapper.CaseDao;
import com.caseProcess.mapper.CaseProcInfoDao;
import com.caseProcess.mapper.DepartmentDao;
import com.caseProcess.service.CaseProcInfoService;
import com.caseProcess.service.CaseService;
import com.caseProcess.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CaseProcInfoServiceImpl implements CaseProcInfoService {

    @Resource
    CaseProcInfoDao caseProcInfoDao;

    @Autowired
    private CaseService caseService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insert(CaseProcInfo caseProcInfo) throws Exception {
        Case cases = new Case();
        cases.setIsStartProcess(true);
        cases.setCaseId(caseProcInfo.getCases().getCaseId());
        try {
            caseService.update(cases);
            caseProcInfoDao.insert(caseProcInfo);
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
        return true;
    }

    @Override
    public int update(CaseProcInfo caseProcInfo) {
        return caseProcInfoDao.update(caseProcInfo);
    }

    @Override
    public int delete(String processId) {
        return caseProcInfoDao.delete(processId);
    }

    @Override
    public List<CaseProcInfo> selectCaseProcInfos(CaseProcInfo caseProcInfo) {
        return caseProcInfoDao.selectCaseProcInfos(caseProcInfo);
    }

    @Override
    public CaseProcInfo getCaseProcInfos(String processId) {
        return caseProcInfoDao.getCaseProcInfos(processId);
    }
}
